package utils;

import org.apache.commons.lang3.ObjectUtils;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class DateUtils {

    /**
     * @param dateArray DateArray string[]
     * @return Does the date comply with the specifications
     */
    public static boolean checkDateArray(String[] dateArray) {
        if (ObjectUtils.isEmpty(dateArray) || dateArray.length == 0) {
            return false;
        }
        for (String dateStr : dateArray) {
            if (!isValidDateFormat(dateStr)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isValidDateFormat(String dateStr) {
        String DATE_PATTERN = "^\\d{4}-\\d{2}-\\d{2}$";
        if (dateStr == null || !dateStr.matches(DATE_PATTERN)) {
            return false;
        }
        try {
            DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
            formatter.parseDateTime(dateStr);
            return true;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

}
